struct ListNode* reverseBetween(struct ListNode* head, int left, int right) {
  if (head == NULL || head->next == NULL) {
        return head;
    }
    
    struct ListNode *dummy = malloc(sizeof(struct ListNode));
    dummy->next = head;
    struct ListNode *pre = dummy;
    
    for (int i = 1; i < left; i++) {
        pre = pre->next;
    }
    
    struct ListNode *cur = pre->next;
    for (int i = left; i < right; i++) {
        struct ListNode *temp = cur->next;
        cur->next = temp->next;
        temp->next = pre->next;
        pre->next = temp;
    }
    
    return dummy->next;
}